package com.wondertek.poms.dao.po;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.wondertek.poms.common.constant.CurrentUser;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Proxy;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;

/**
 * <p><b>PcProductPermission Description:</b> PcProductPermission po类 ; 产品权限表</p>
 *
 * @author 高正行
 * <p><b>DATE</b> 2019-08-12 11:20:52</p>
 */
@SuppressWarnings("JpaDataSourceORMInspection")
@Data
@Entity
@Table(name = "pc_product_permission")
@DynamicUpdate
@DynamicInsert
@Proxy(lazy = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PcProductPermission implements java.io.Serializable {

    /**
     * <b>Fields</b> serialVersionUID :
     */
    private static final long serialVersionUID = 1554955798741285268L;

    /**
     * <b>Fields</b> id : 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_PERMISSION_CONFIG_ID")
    @SequenceGenerator(name = "SEQ_PERMISSION_CONFIG_ID", sequenceName = "SEQ_PERMISSION_CONFIG_ID", allocationSize = 1)
    private Long id;

    /**
     * <b>Fields</b> fsPrdId : 一二级产品ID/商品包ID 外键
     */
    @Column(name = "fs_prd_id")
    private Long fsPrdId;

    /**
     * <b>Fields</b> prdLevel : 产品级别 1 一级 2 二级 3 商品包
     */
    @Column(name = "prd_level")
    private Integer prdLevel;

    /**
     * <b>Fields</b> userType : 类型 1用户 2 群组
     * 这个字段全部为1   这个表只针对用户，不再针对用户组
     */
    @Column(name = "user_type")
    private Integer userType;

    /**
     * <b>Fields</b> ugid : 用户ID
     */
    private Long ugid;

    /**
     * <b>Fields</b> ugid : 用户组ID或者用户ID
     * USER_OR_GROUP_ID
     */
//    @Column(name = "user_or_group_id")
//    private Long userOrGroupId;

    /**
     * <b>Fields</b> ugname : 用户名称或用户组名称
     */
    private String ugname;

    /**
     * <b>Fields</b> createdBy : 创建人
     */
    @Column(name = "created_by")
    private String createdBy;

    /**
     * <b>Fields</b> createdTime : 创建时间 YYYY-MM-DD HH24:MI:SS
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "created_time")
    private java.time.LocalDateTime createdTime;

    /**
     * <b>Fields</b> updatedBy : 更新人
     */
    @Column(name = "updated_by")
    private String updatedBy;

    /**
     * <b>Fields</b> updatedTime : 更新时间 YYYY-MM-DD HH24:MI:SS
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "updated_time")
    private java.time.LocalDateTime updatedTime;

    /**
     * <b>Fields</b> remarks : 备注
     */
    private String remarks;

    /**
     * <b>Fields</b> deleted : 是否删除 1是0否
     */
    private Integer deleted = 0;

    /**
     * isShow 1：是勾选；0不勾选
     */
    @Column(name = "is_show")
    private Integer isShow;

    public PcProductPermission() {

    }

    public PcProductPermission(Long ugid, String ugname, Integer userType) {
        this.userType = userType;
        this.ugid = ugid;
        this.ugname = ugname;
    }

    public static void putTimeAndUser(PcProductPermission pcProductPermission) {
        if (pcProductPermission.id == null) {
            pcProductPermission.setCreatedBy(CurrentUser.currUserName());
            pcProductPermission.setCreatedTime(java.time.LocalDateTime.now());
        }
        pcProductPermission.setUpdatedBy(CurrentUser.currUserName());
        pcProductPermission.setUpdatedTime(java.time.LocalDateTime.now());
    }
}